<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:composite="http://java.sun.com/jsf/composite">

<composite:interface>
	<composite:attribute name="updateElement" />
	<composite:attribute name="oncomplete" />
	<composite:attribute name="parentFormId" required="true"
		default="itemsForm" />
	<composite:attribute name="selectButtonRendered" default="true" />
	<composite:attribute name="returnAction"
		method-signature="void getSelectedItem(javax.faces.event.ActionEvent)"></composite:attribute>
</composite:interface>

<composite:implementation>
	<p:dataTable id="#{cc.id}" var="item" value="#{itemsMB.items}"
		rowKey="#{item.id}" selectionMode="single"
		emptyMessage="No se han encontrado items"
		filteredValue="#{itemsMB.itemsFiltrados}"
		rowsPerPageTemplate="5,10,15" selection="#{itemsMB.selectedItem}">
		<p:ajax event="rowSelect" listener="#{itemsMB.rowSelected}"
			update="selectButton" />

		<p:column style="width:2%">
			<p:rowToggler />
		</p:column>
		<p:column id="codigoCol" filterBy="#{item.codigo}" headerText="Codigo"
			filterMatchMode="contains">
			<h:outputText value="#{item.codigo}" />
		</p:column>
		<p:column id="descCol" filterBy="#{item.descripcion}"
			headerText="Descripción" filterMatchMode="contains">
			<h:outputText value="#{item.descripcion}" />
		</p:column>
		<p:column id="tipoItemCol" filterBy="#{item.itemTipo}"
			headerText="Tipo" filterOptions="#{itemsMB.itemTipos}"
			filterMatchMode="exact">
			<h:outputText value="#{item.itemTipo}" />
		</p:column>
		<p:column id="anchoCol" headerText="Ancho">
			<h:outputText value="#{item.ancho}" />
		</p:column>
		<p:column id="espCol" headerText="Espesor">
			<h:outputText value="#{item.espesor}" />
		</p:column>
		<p:column id="pesoCol" headerText="Peso">
			<h:outputText value="#{item.peso}">
				<f:convertNumber maxFractionDigits="1"></f:convertNumber>
			</h:outputText>
		</p:column>
		<p:column id="largoCol" headerText="Largo">
			<h:outputText value="#{item.largo}" />
		</p:column>
		<p:rowExpansion>
			<p:panelGrid styleClass="table table-bordered table-striped">
				<p:row>
					<p:column styleClass="tableNoGrid">
						<p:panelGrid>
							<p:row>
								<p:column>
									<h:outputText style="font-weight: bold;"
										value="Descripcion del Articulo"></h:outputText>
								</p:column>
								<p:column>
									<h:outputText value="#{item.descripcion}" />
								</p:column>
							</p:row>
						</p:panelGrid>
					</p:column>
				</p:row>
			</p:panelGrid>
		</p:rowExpansion>


		<f:facet name="footer">
			<p:commandButton id="selectButton"
				actionListener="#{cc.attrs.returnAction}" value="Agregar"
				disabled="#{!itemsMB.rowSelected}"
				update="#{cc.attrs.updateElement}" icon="ui-icon-arrowthick-1-n"
				rendered="#{cc.attrs.selectButtonRendered}"
				oncomplete="#{cc.attrs.oncomplete}" process="@this" />
		</f:facet>
	</p:dataTable>
</composite:implementation>

</html>